#include "Comm.hpp"
#include "Fifo.hpp"

int main()
{
    key_t key = getkeyOrdie();
    cout << "key: " << ToHex(key) << endl;

    int shmid = GetShm(key, defaultsize);
    cout << "shmid: " << shmid << endl;

    //挂接
    char* addr = (char*)AttachShm(shmid);
    cout << "attach success" << endl;

    memset(addr, 0, defaultsize);
    Sync syn;
    syn.OpenWrite();

    //通信
    for(int i='A'; i<='Z'; i++)
    {
        addr[i-'A'] = i;
        sleep(1);
        syn.Wakeup();
    }

    //去挂接
    DetachShm(addr);
    cout << "detach success" << endl;
    sleep(5);

    return 0;
}